﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace depl
{
    class SearchCache
    {
        List<DictEntry>[] cache = new List<DictEntry>[PivotPage1.MAX_INPUT_LENGTH];

        public void Store(int idx, List<DictEntry> entriesToStore)
        {
            cache[idx] = entriesToStore;
            cache[idx].ForEach(delegate(DictEntry entry)
            {
                Debug.WriteLine("Storing Cache["+idx+"]: "+entry.Name);
            });
            
        }

        public void Clear(int idx)
        {
            cache[idx] = null;
        }

        public void Clear()
        {
            Debug.WriteLine("Clearing whole Cache");
            for (int i = 0; i < cache.Length; i++ )
            {
                cache[i] = null;
            }
        }

        public List<DictEntry> Load(int idx)
        {
            
            List<DictEntry> retval = cache[idx];
            if (retval != null)
            {
                cache[idx].ForEach(delegate(DictEntry entry)
                {
                    Debug.WriteLine("Loading Cache[" + idx + "]: " + entry.Name);
                });
            }
            else
            {
                Debug.WriteLine("SearchCache Load [" + idx + "] is null");
            }
            cache[idx] = null;
            return retval;
        }
    }
}
